program q1020;
var
    n, i, j, ans, s_len: integer;
    s: string;
begin
    assign(input, '');
    assign(output, '');
    reset(input);
    rewrite(output);

    readln(n);

    while (n > 0) do
    begin
        readln(s);
        s_len := length(s);

        i := 1;
        while (i < s_len) do
        begin
            ans := 1;
            j := i + 1;
            while (s[i] = s[j]) and (j <= s_len) do
            begin
                inc(j); inc(ans);
            end;

            if (ans > 1) then
            begin
                write(ans);
                i := j - 1;
            end;

            write(s[i]);
            inc(i);
        end;
        writeln;

        dec(n);
    end;

    close(input);
    close(output);
end.
